package newcoder;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class beike {

    static int max = Integer.MIN_VALUE;
    public static void dfs(List<List<Integer>> rs ,int len ,int curLen,int[] counts){
        if (curLen == len){
            int sum = 0;
            for (int i = 0 ; i < counts.length ; i++){
                sum += Math.pow(counts[i],2);
            }
            if (sum > max){
                max = sum;
            }
            Stack<Character> stack = new Stack<>();
            return;
        }
        for (int i = rs.get(curLen).get(0) ; i <= rs.get(curLen).get(1) ; i++){
            counts[i-1]++;
            curLen++;
            dfs(rs,len,curLen,counts);
            curLen--;
            counts[i-1]--;

        }
    }


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int row = scanner.nextInt();
        int col = scanner.nextInt();
        List<List<Integer>> rs = new ArrayList<>();
        for (int i = 0 ; i < row ; i++){
            int num = scanner.nextInt();
            for (int j = 0 ; j < num ; j++){
                List<Integer> tempList = new ArrayList<>();
                tempList.add(scanner.nextInt());
                tempList.add(scanner.nextInt());
                rs.add(tempList);
            }

        }
        int[] counts = new int[col];
        dfs(rs,rs.size(),0,counts);
        System.out.println(max);
    }
}
